<template>
	<view class="post-item p-2 animated fast fadeIn">
		<view class="flex align-center">
			<image class="post-avatar rounded-circle" :src="item.userpic!==null ? item.userpic : '/static/default.jpg'" lazy-load @click="openDetail" @error="onImageLoadError(item)"></image>
			<view class="flex flex-column ml-2" @click="openDetail">
				<text class="text-dark font">{{item.username}}</text>
				<text class="text-muted">{{item.newstime | formatTime}}</text>
			</view>
			<view v-if="!item.isFollow" class="follow-btn flex align-center justify-center rounded bg-main text-white ml-auto animated " hover-class="jello" @click="onFollow">关注
			</view>
		</view>
		<view class="flex align-center">
			{{item.title}}
		</view>
		<image v-if="item.titlepic" class="w-100 rounded my-1" :src="item.titlepic" mode="aspectFill" lazy-load></image>
		<view class="flex align-center  py-2" >
			<view class="flex align-center justify-center flex-1 animated" hover-class="jello">
				<text class="iconfont icon-dianzan2"></text>
				<text class=" ml-2">{{item.support['support_count']>0?item.support['support_count']:'踩'}}</text>
			</view>
			<view class="flex align-center justify-center flex-1 animated" hover-class="jello">
				<text class="iconfont icon-cai"></text>
				<text class=" ml-2">{{item.support['unsupport_count']>0?item.support['unsupport_count']:'踩'}}</text>
			</view>
			<view class="flex align-center justify-center flex-1 animated" hover-class="jello">
				<text class="iconfont icon-pinglun2"></text>
				<text class="ml-2">{{item.comment_count >0 ? item.comment_count :'评论'}}</text>
			</view>
			<view class="flex align-center justify-center flex-1 animated" hover-class="jello">
				<text class="iconfont icon-zhuanfa1"></text>
				<text class="ml-2">{{item.share_num >0 ? item.share_num : '分享'}}</text>
			</view>
		</view>
	</view>
</template>
<script>
	import $T from '@/common/time.js'
	export default {
		props:{
			item:{
				type:Object,
				default:{}
			},
			index:Number
		},
		filters:{
			formatTime(val) {
				return $T.gettime(val)
			}
		},
		methods:{
			// 关注
			onFollow() {
				this.checkAuth(()=> {
					this.$emit('onFollow',this.item,this.index)
				})
			},
			// 图片加载失败
			onImageLoadError(item){
				item.userpic = '/static/default.jpg'
			},
			// 进入个人空间
			openDetail() {
				this.checkAuth(()=> {
					uni.navigateTo({
						url:'/pages/user-detail/user-detail'
					})
				})
				
			}
		}
	}
</script>
<style lang="scss" scoped>
	.post-item {
		.post-avatar {
			width: 66rpx;
			height: 66rpx;
		}
		.follow-btn {
			width: 92rpx;
			height: 50rpx;
		}
	}
</style>